package com.sky.controller.admin;

import com.github.pagehelper.Page;
import com.sky.dto.ConfirmDTO;
import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
@Api("管理端 订单相关接口")
@Slf4j
public class OrdersController {
    @Autowired
    private OrderService orderService;
    @ApiOperation("分页查询订单")
    @GetMapping("/conditionSearch")
    public Result<PageResult> page(OrdersPageQueryDTO pageQueryDTO){
        log.info("订单分页查询:{}",pageQueryDTO);
        PageResult pageResult = orderService.pageQuery(pageQueryDTO);
        return Result.success(pageResult);
    }
    @GetMapping("/statistics")
    @ApiOperation("请求订单状态")
    public Result<OrderStatisticsVO> statistics(){
        log.info("请求订单状态");
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();
        return Result.success(orderStatisticsVO);
    }

    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result confirm(@RequestBody ConfirmDTO confirmDTO){
        log.info("接单ID:{}",confirmDTO.getId());
        orderService.confirm(confirmDTO.getId());
        return Result.success();
    }
    @PutMapping("/delivery/{id}")
    @ApiOperation("派送")
    public Result delivery(@PathVariable Long id){
        log.info("派送ID{}",id);
        orderService.delivery(id);
        return Result.success();
    }
    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result complete (@PathVariable Long id){
        log.info("完成订单:{}",id);
        orderService.complete(id);
        return Result.success();
    }
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel (@RequestBody OrdersCancelDTO dto){
        orderService.cancel(dto);
        return Result.success();
    }

    @GetMapping("/details/{id}")
    @ApiOperation("查看订单")
    public Result<OrderVO> details (@PathVariable Long id){
        OrderVO orderVO = orderService.details(id);
        return Result.success(orderVO);
    }
}
